#include "ShooterManager.h"
#include "CollisionManager.h"

namespace PeanutQuest {

	ShooterManager::ShooterManager(std::string id) : cg::Entity(id) {
	}
	ShooterManager::~ShooterManager() {
	}

	void ShooterManager::init() {

		rock_weapon = false;
		wood_weapon = false;

		woodCounter = 0;
		rockCounter = 0;

		wasShot = false;
	}

	void ShooterManager::update(unsigned long elapsed_millis) {
		_cm = (CollisionManager*)cg::Registry::instance()->get("CollisionManager");

	}

	void ShooterManager::onKeyPressed(unsigned char key) {
		if(key == 'c') {
			setMessage("");
			rockWeapon();	
		}
		if(key == 'v') {
			setMessage("");
			woodWeapon();	
		}
		if(key == 'x') {
			setMessage("");
			shoot();	
		} 
	}

	void ShooterManager::onKeyReleased(unsigned char key) {
		if(key == 'x') {
			wasShot = false;
		} 
	}

	void ShooterManager::rockWeapon() {
		rock_weapon = true;
		wood_weapon = false;
	}

	void ShooterManager::woodWeapon() {
		wood_weapon = true;
		rock_weapon = false;
	}

	void ShooterManager::shoot() {
		// wood selected - v
		if(wood_weapon) {
			if(woodCounter > 0) {
				woodCounter--;
				wasShot = true;
			}
			else {
				setMessage("You don't own any wooden sticks!");
			}
		}
		// rock selected - c
		else if(rock_weapon) {
			if(rockCounter > 0) {
				rockCounter--;
				wasShot = true;
			}
			else {
				setMessage("You don't own any rocks!");
			}
		}
		// any weapon selected
		else {
			setMessage("You still haven't selected weapons.");
		}
	}

	void ShooterManager::setMessage(std::string message) {
		_message = message;
	}

	std::string ShooterManager::getMessage() {
		return _message;
	}

}